package com.xpmusic.dao.impl;

import com.xpmusic.dao.ConsumerDAO;
import com.xpmusic.model.ConsumerInfo;
import com.xpmusic.util.DBUtil;
import org.apache.ibatis.session.SqlSession;

public class ConsumerDaoImpl implements ConsumerDAO {

    /**
     * 注册用户
     * @param consumerInfo
     * @return
     */
    public boolean insertConsumerInfo(ConsumerInfo consumerInfo) {
        boolean flag = false;
        SqlSession sqlSession = DBUtil.openSessionConnection();
        int i = sqlSession.insert("consumer.insertConsumerInfo",consumerInfo);
        flag = i == 1;
        sqlSession.commit();//提交
        sqlSession.close();
        DBUtil.close();
        return flag;
    }

    /**
     * 判断用户注册时候是否已经存在用户名
     * @param loginName
     * @return
     */
    public boolean checkUserName(String loginName) {
        boolean flag = false;
        SqlSession sqlSession = DBUtil.openSessionConnection();
        int i = sqlSession.selectOne("consumer.checkUserNameByName",loginName);
        flag = i == 1;
        sqlSession.close();
        DBUtil.close();
        return flag;
    }

    /**
     * 验证用户登陆信息
     * @param consumerInfo
     * @return boolean
     */
    public boolean checkConsumerInfo(ConsumerInfo consumerInfo) {
        boolean flag = false;
        SqlSession sqlSession = DBUtil.openSessionConnection();
        int i = sqlSession.selectOne("consumer.checkConsumerInfo",consumerInfo);
        flag = i ==1;
        sqlSession.close();
        DBUtil.close();
        return flag;
    }
}
